package com.cdream.basic.algorithm.leetcode.dp;

public class Question53 {
    public int maxSubArray(int[] nums) {
        if(nums.length==1){
            return nums[0];
        }
        int[] dp = new int[nums.length + 1];
        dp[0] = nums[0];
        dp[1] = Math.max(nums[1], nums[1] + nums[0]);
        int res = Math.max(dp[0],dp[1]);
        for (int i = 2; i < nums.length; i++) {
            dp[i] = Math.max(nums[i], dp[i - 1] + nums[i]);
            res = Math.max(res,dp[i]);
        }
        return res;

    }

    public static void main(String[] args) {
        new Question53().maxSubArray(new int[]{-2, 1});
    }
}
